package com.xiaouyudeguang.common.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.xiaouyudeguang.common.utils.EncryptUtils;
import com.xiaouyudeguang.common.utils.StringUtils;

import java.io.IOException;

/**
 * 加密
 */
public class EncryptJsonDeserializer extends JsonDeserializer<String> {

    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        return StringUtils.isBlank(jsonParser.getText()) ? null : EncryptUtils.encrypt(jsonParser.getText());
    }
}